<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>抽奖后短信发送</title>
<base href="<%=basePath %>" />
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/icon.css">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/color.css">
	<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
</head>
<body>
<!-- 抽奖搜索 -->
	 <div style="height: 40px; width: 100%;">
		<div style="float: left; padding:10px 0 0 10px; ">   
		        <label for="">项目名:</label>   
		        <input class="easyui-textbox" type="text" name="lprojectTitle" id="lprojectTitle"  />   
    	</div> 
    	<div style="float: left; padding:10px 0 0 10px; ">   
		        <label for="">回报名:</label>   
		        <input class="easyui-textbox" type="text" name="litemTitle" id="litemTitle"  />   
    	</div> 
    	<div style="float: left; padding:10px 0 0 10px; ">   
		        <label for="">是否发送短信:</label>   
		        <select id="lsendSMS" class="easyui-combobox" name="lsendSMS" 
		        style="width:200px;" data-options="editable:false,panelHeight:'auto'">
				    <option value="" selected="selected">请选择</option>
				    <option value="1">否</option>
				    <option value="2">是</option>
				</select> 
    	</div>
    	<div style="float: left; padding:10px 0 0 10px; ">    
    		<button  id="searchLottery" class="easyui-linkbutton c1" data-options="iconCls:'icon-search'" type="button">查询 </button>
   		  </div> 
	      <div style="float: left; padding:10px 0 0 10px; ">    
	    	<button  id="resetLottery" class="easyui-linkbutton c5" data-options="iconCls:'icon-no'" type="button">重置 </button>
	      </div> 
	</div>
	<br />
	<div id="toolbar">
		<c:forEach items="${list}" var="item">
				${item}
		</c:forEach>
	</div>
	<div id="choujiang_table"></div>
</body>
<script type="text/javascript">
$(function(){
		   $('#choujiang_table')
			.datagrid(
					{
						url : 'admin/queryqueryLotteryedInfo.do?pageSize=10',
						collapsible : true,
						width : '100%',
						height :'350px',
						iconCls : 'icon-user',
						fitColumns : true,
						pagination : true,
						rownumbers : true,
						singleSelect:false,
						checkOnSelect:true,
						selectOnCheck:true,
						idField:'loanid',
						loadMsg:'正在加载数据',
						loadFilter:function(data){
							for(var i=0;i<data.rows.length;i++){
								if(data.rows[i].orderPayStatus=='1'){
									data.rows[i].orderPayStatus='已支付';
								}
								if(data.rows[i].orderPayStatus=='2'){
									data.rows[i].orderPayStatus='未支付';
								}
								if(data.rows[i].itemAwardStatus=='3'){
									data.rows[i].itemAwardStatus='已抽奖';
								}
								if(data.rows[i].sendSMS=='1'){
									data.rows[i].sendSMS='否';
								}
								if(data.rows[i].sendSMS=='2'){
									data.rows[i].sendSMS='是';
								}
						}
							 return data;
						},
						onClickRow: function(rowIndex, rowData) {
							//layer.msg("选中");
							
						},
						onDblClickRow :function(rowIndex,rowData){
							//layer.msg("double click");
						  },
						toolbar:'#toolbar'/* [{
							id:'btnedit',
							text:'发送短信',
							iconCls:'icon-add',
							handler:function(){
								
							}
						},{
							id:'export',
							text:'导出中奖名单',
							iconCls:'icon-export',
							handler:function(){
								layer.msg('敬请期待');
							}
						}
						] */,
						columns : [ [
						             	{
						             		field:'ck',
			                               checkbox:true,
			                               align : 'center'
										},
										{
											field : 'projectTitle',
											title : '项目名',
											width : 50,
											align : 'center'
										}, 
										{
											field : 'itemTitle',
											title : '回报名',
											width : 50,
											align : 'center'
										}, 
										{
											field : 'itemAwardStatus',
											title : '抽奖情况',
											width : 50,
											align : 'center'
										},{
											field : 'sendSMS',
											title : '是否发送短信',
											width : 50,
											align : 'center'
										},
										{
											field : 'orderPrice',
											title : '订单价格',
											width : 50,
											align : 'center'
										},
										{
											field : 'orderPayStatus',
											title : '支付状态',
											width : 50,
											align : 'center'
										},
										{
											field : 'orderCreateTime',
											title : '订单创建时间',
											width : 50,
											align : 'center'
										},
										{
											field : 'lotteryCreateTime',
											title : '中奖时间',
											width : 50,
											align : 'center'
										},
										{
											field : 'userName',
											title : '支付人',
											width : 50,
											align : 'center'
										},{
											field : 'userTelephone',
											title : '支付人电话',
											width : 50,
											align : 'center'
										}
									   ] ]
					});
		 //设置分页控件  
			
		var p = $('#choujiang_table').datagrid('getPager');
			$(p).pagination({
				pageSize : 10,//每页显示的记录条数，默认为10  
				pageList : [ 5, 10, 20, 30, 40, 50 ],//可以设置每页记录条数的列表  
				beforePageText : '第',//页数文本框前显示的汉字  
				afterPageText : '页    共 {pages} 页',
				displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
				onSelectPage : function(pageNumber, pageSize) {
					//layer.msg("pageNumber="+pageNumber+"pageSize="+pageSize)
					var datas = {
						projectTitle:$("#sprojectTitle").textbox('getValue'),
						itemTitle:$("#sitemTitle").textbox('getValue'),
						currentPage : (pageNumber - 1) * pageSize,
						pageSize : pageSize
					}
					loadchoujiangData(datas);
				},
				onRefresh : function(pageNumber, pageSize) {
					var datas = {
							projectTitle:$("#sprojectTitle").textbox('getValue'),
							itemTitle:$("#sitemTitle").textbox('getValue'),
							currentPage : (pageNumber - 1) * pageSize,
							pageSize : pageSize
						}
					loadchoujiangData(datas);
				}
			});
		//toolbar 
		$(function(){
			$('#send').bind('click',function(){
				var rows = $('#choujiang_table').datagrid('getSelections');
				if(rows.length!=0){
					var tel="";
					var project ="";
					var item = "";
					var lotteryId="";
					for(var i =0; i<rows.length;i++){
						if(rows[i].sendSMS=="是"){
							layer.msg('存在发送短信的中奖订单');
							break;
						}else{
							tel+=rows[i].userTelephone+",";
							project+=rows[i].projectTitle+",";
							item+=rows[i].itemTitle+",";
							lotteryId+=rows[i].lotteryId+",";
							layer.confirm('确定发送短信吗？', {
								  btn: ['确定','再想想'] //按钮
								}, function(){
									 $.ajax({
											url : 'admin/sendChoujiangSMS.do',
											type : "POST",
											dataType : "json",						
											data : {
												'tel':tel,
												'projectTitle':project,
												'itemTitle':item,
												'lotteryId':lotteryId,
											},
											success : function(result) {
												layer.msg(result.tips);
												$('#choujiang_table').datagrid('clearSelections')
												$('#choujiang_table').datagrid('reload');
											}
									});  
								}, function(){
								  layer.msg('请仔细检查数据');
								});
						}
					}
					
				}else{
					layer.msg('未选中');
				}
			});
		});
		//search btn
		$("#searchLottery").click(function(){
			var pageSize = $('#choujiang_table').datagrid('getPager').data("pagination").options.pageSize;
			var datas={
					pageSize:pageSize,
					projectTitle:$("#lprojectTitle").textbox('getValue'),
					itemTitle:$("#litemTitle").textbox('getValue'),
					sendSMS:$("#lsendSMS").combobox('getValue'),
					
			}
			loadchoujiangData(datas);
		});
		//resetValue btn 
		$("#resetLottery").click(function(){
			$("#lprojectTitle").textbox('setValue','');
			$("#litemTitle").textbox('setValue','');
			$("#lsendSMS").combobox('setValue','');
			var pageSize = $('#choujiang_table').datagrid('getPager').data("pagination").options.pageSize;
				var datas = {
					pageSize : pageSize,
				}
				loadchoujiangData(datas);
		});
		
		//load datas
		var loadchoujiangData=function(datas){
			 $.ajax({
					url : 'admin/queryqueryLotteryedInfo.do',
					type : "POST",
					dataType : "json",						
					data : datas,
					success : function(param) {
							$('#choujiang_table').datagrid('clearSelections')
							$('#choujiang_table').datagrid('loadData',param);
					}
			});  
		}
});
</script>
</script>
</html>